<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>产品网登入界面</title>
</head>

<body>
    <table id="table">
        <tr>
            <h1>请登入</h1>
        </tr>
        <tr>
            <td>
                用户名：
            </td>
            <td>
                <input type="text" name="username">
            </td>
        </tr>
        <tr>
            <td>
                密码：
            </td>
            <td>
                <input type="password" name="password">
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="登入" onclick="login()">
            </td>
            <td>
                <input type="button" value="取消" onclick="cancal()">
            </td>
        </tr>
    </table>
    <script src="./jquery-3.6.0.min.js"></script>
    <script>
        //登入界面
        function login() {
            let username = $('[name = "username"]').val()
            let password = $('[name = "password"]').val()
            let obj = {
                username,
                password
            }
            $.post('http://localhost:8000/login', obj, (res) => {
                if (res['code'] === 200) {
                    window.location.href = 'info.html';
                } else {
                    alert(res['msg'])
                }
            })
        }
        //取消登入
        function cancal() {
            window.location.href = 'index.html';
        }
    </script>
</body>

</html>